<%-- 
    Document   : func_logistics_bill_approval
    Created on : 2018-5-27, 21:34:28
    Author     : Dannis
--%>

<%@page import="com.antexpress.common.Const"%>
<%@page import="com.antexpress.pojo.Employee"%>
<%@page import="com.antexpress.bean.Authentication"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Express -- Ant Express</title>
        <link rel="shortcut icon" href="static/img/ant-logo.png">
        <link href="static/css/style.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/normalize.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/default.css" rel="stylesheet" type="text/css"/>
        <link href="static/dist/css/jquery.secretnav.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/demo.css" rel="stylesheet" type="text/css"/>
        <link href="static/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/edbox.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/selectpage.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/stickysort.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <%
            if (!Authentication.isLogin(session)) {
                response.sendRedirect("index.jsp");
                return;
            }
            Employee emp = (Employee) session.getAttribute(Const.CURRENT_USER);
            if (!Authentication.isHRAdmin(emp) && !Authentication.isExpressAdmin(emp)
                    && !Authentication.isExpressCourier(emp) && !Authentication.isExpressAreaManager(emp)
                    && !Authentication.isExpressLogisticsApproval(emp) && !Authentication.isExpressLogisticsManager(emp)) {
                response.sendRedirect("404.jsp");
                return;
            }
        %>
        <div class="sn-outer-wrapper sn-moveleft modalview">
            <div class="sn-content-wrapper transform" style="cursor: default;">
                <div id="content" style="top: 0px;">
                    <jsp:include page="ui/header.jsp"/>
                    <div class="container-nav">
                        <div class="container">
                            <button class="open btn btn-default bt-open" title="Menu"><i class="fa fa-bars" aria-hidden="true"></i></button>
                            <!--此处可以扩展其他的功能-->
                            <%
                                if (Authentication.isExpressLogisticsManager(emp)) {
                                    out.println("<a href='express_courier.jsp' class='content-nav-bt'>Courier Management</a>");
                                    out.println("<a href='express_area_manager.jsp' class='content-nav-bt'>Area Manager Management</a>");
                                    out.println("<a href='express_logistics_approval.jsp' class='content-nav-bt'>Logistics Approval Management</a>");
                                }
                            %>
                        </div>
                    </div>
                    <div class="container" style="text-align: left;color: #000">
                        <h1 class="heading"><i class="fa fa-book" aria-hidden="true"></i> New Sending Bills</h1>
                        <div class="content-div">
                            <table id="page-table" class="pub-table pub-table-hover" style="margin-top: 20px;">
                                <thead>
                                    <tr>
                                        <th>&nbsp;<i class="fa fa-check-square-o" aria-hidden="true"></i>&nbsp;</th>
                                        <th>BillID</th>
                                        <th>Consignor</th>
                                        <th>City</th>
                                        <th>Consignee</th>
                                        <th>City</th>
                                        <th>&nbsp;<i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;</th>
                                    </tr>
                                </thead>
                                <tbody id="bill-table-body">

                                </tbody>
                            </table>
                            <div id="searchResultMsg" class="content-center table-result-msg">

                            </div>
                            <!--详细信息模态框-->
                            <div id="bill-show-box" class="ed-div" style="display:none;">
                                <h3 class="subheading" style="margin: 3px;"><i class="fa fa-info-circle" aria-hidden="true"></i> Bill Details</h3><br/>
                                <table class="model-form-table" style="color: black;">
                                    <tr>
                                        <td>BillID</td>
                                        <td id="bill-show-billID"></td>
                                    </tr>
                                    <tr>
                                        <td>ConsignorName</td>
                                        <td id="bill-show-ConsignorName"></td>
                                    </tr>
                                    <tr>
                                        <td>ConsignorCity</td>
                                        <td id="bill-show-ConsignorCity"></td>
                                    </tr>
                                    <tr>
                                        <td>ConsigneeName</td>
                                        <td id="bill-show-ConsigneeName"></td>
                                    </tr>
                                    <tr>
                                        <td>ConsigneeCity</td>
                                        <td id="bill-show-ConsigneeCity"></td>
                                    </tr>
                                    <tr>
                                        <td>Weight</td>
                                        <td id="bill-show-Weight"></td>
                                    </tr>
                                    <tr>
                                        <td>Amount</td>
                                        <td id="bill-show-Amount"></td>
                                    </tr>
                                    <tr>
                                        <td>Freight</td>
                                        <td id="bill-show-Freight"></td>
                                    </tr>
                                    <tr>
                                        <td>PayWay</td>
                                        <td id="bill-show-PayWay"></td>
                                    </tr>
                                    <tr>
                                        <td>Insurance</td>
                                        <td id="bill-show-Insurance"></td>
                                    </tr>
                                    <tr>
                                        <td>Commits</td>
                                        <td id="bill-show-Commits"></td>
                                    </tr>
                                </table>
                                <input type="button" id="bt-add-emp-cancel" onclick="passbill()" class="btn btn-default" value="Pass"/>
                                <input type="button" id="bt-add-emp-cancel" onclick="$.edbox('close');" class="btn btn-default" value="Close"/>
                            </div><!-- 展示订单信息模态框 结束 -->
                        </div>



                    </div>
                </div>
            </div>
            <div class="sn-nav-wrapper">
                <nav id="nav" class="sn-nav left vertical">
                    <jsp:include page="ui/nav.jsp"/>
                </nav>
            </div>
        </div>
        <script src="static/js/modernizr.custom.25376.js" type="text/javascript"></script>
        <script src="static/js/jquery.js" type="text/javascript"></script>
        <script src="static/js/common-script.js" type="text/javascript"></script>
        <script src="static/dist/js/jquery.secretnav.js" type="text/javascript"></script>
        <script src="static/js/jquery.ba-throttle-debounce.min.js" type="text/javascript"></script>
        <script src="static/js/jquery.edbox.js" type="text/javascript"></script>
        <script src="static/js/selectpage.js" type="text/javascript"></script>
        <script src="static/js/jquery.stickysort.js" type="text/javascript"></script>
        <script>
                                    $(function () {
                                        menu();
                                        $("#page-table").stickySort();
                                        initBillList();
                                    });
                                    function initBillList() {
                                        getBillList(1);
                                    }
                                    function getBillList(pageNo) {
                                        $("#searchResultMsg").empty();
                                        $.ajax({
                                            url: "${pageContext.request.contextPath}/express/list_bills_status0.do",
                                            data: {
                                                "pageNo": pageNo
                                            },
                                            type: "POST",
                                            dataType: "json",
                                            success: function (result) {
                                                if (result.status === 1) {
                                                    var billList = result.data.list;
                                                    if (billList.length === 0) {
                                                        $("#searchResultMsg").append("No Record!!");
                                                    } else {
                                                        buildBillTable(billList);
                                                    }
                                                } else {
                                                    $.edbox({danger: result.msg});
                                                }
                                            },
                                            error: function () {
//                                                $.edbox({danger: "Got failed!"});
                                            }
                                        });
                                    }
                                    function buildBillTable(billList) {
                                        $("#bill-table-body").empty();
                                        var rowNum = 0;
                                        $.each(billList, function () {
                                            rowNum++;
                                            var billCheckbox = $("<td>").append("<input type='checkbox'/>");
                                            var billID = $("<td>").append(this.id);
                                            var consignor = $("<td>").append(this.consignorInfo.name);
                                            var consignor_city = $("<td>").append(this.consignorInfo.mapTown.mapDistrict.mapCity.name);
                                            var consignee = $("<td>").append(this.consigneeInfo.name);
                                            var consignee_city = $("<td>").append(this.consigneeInfo.mapTown.mapDistrict.mapCity.name);
                                            var showBillOp = $("<a href='#' title='Details' edbox data-box-target='#bill-show-box' billID='" + this.id + "' consignorname='" + this.consignorInfo.name + "' consignorcity='" + this.consignorInfo.mapTown.mapDistrict.mapCity.name
                                                    + "' consigneename='" + this.consigneeInfo.name + "' consigneecity='" + this.consigneeInfo.mapTown.mapDistrict.mapCity.name + "' freight='" + this.freight + "' insured='" + this.insured + "' payway='" + this.panment
                                                    + "' weight='" + this.weight + "' commit='" + this.commit + "' amount='" + this.amount + "'></a>")
                                                    .append("<i class='fa fa-pencil-square-o' aria-hidden='true'></i>");

                                            showBillOp.click(function () {
                                                $("#bill-show-billID").empty();
                                                $("#bill-show-billID").append(showBillOp.attr("billID"));
                                                $("#bill-show-ConsignorName").empty();
                                                $("#bill-show-ConsignorName").append(showBillOp.attr("consignorname"));
                                                $("#bill-show-ConsignorCity").empty();
                                                $("#bill-show-ConsignorCity").append(showBillOp.attr("consignorcity"));
                                                $("#bill-show-ConsigneeName").empty();
                                                $("#bill-show-ConsigneeName").append(showBillOp.attr("consigneename"));
                                                $("#bill-show-ConsigneeCity").empty();
                                                $("#bill-show-ConsigneeCity").append(showBillOp.attr("consigneecity"));
                                                $("#bill-show-Weight").empty();
                                                $("#bill-show-Weight").append(showBillOp.attr("weight")).append("KG");
                                                $("#bill-show-Amount").empty();
                                                $("#bill-show-Amount").append(showBillOp.attr("amount"));
                                                $("#bill-show-Freight").empty();
                                                $("#bill-show-Freight").append(showBillOp.attr("freight")).append("$");
                                                $("#bill-show-PayWay").empty();
                                                if (showBillOp.attr("payway") === "0")
                                                    $("#bill-show-PayWay").append("Online");
                                                else {
                                                    $("#bill-show-PayWay").append("Pay On Delivery");
                                                }
                                                $("#bill-show-Insurance").empty();
                                                $("#bill-show-Insurance").append(showBillOp.attr("insured"));
                                                $("#bill-show-Commits").empty();
                                                $("#bill-show-Commits").append(showBillOp.attr("commit"));
                                            });
                                            showBillOp.edbox();
                                            var billOp = $("<td>").append(showBillOp).append("&nbsp;&nbsp;&nbsp;");
//                                            列表身体赋值
                                            var billRow = $("<tr>").append(billCheckbox).append(billID).append(consignor)
                                                    .append(consignor_city).append(consignee).append(consignee_city).append(billOp);
                                            if (rowNum % 2 === 0)
                                                billRow.addClass("td-bk");
                                            $("#bill-table-body").append(billRow);
                                        });
                                    }
                                    function passbill() {
                                        $.ajax({
                                            url: "${pageContext.request.contextPath}/express/passStatus0bill.do",
                                            data: {
                                                "billinfoID": $("#bill-show-billID").text()
                                                        //向后端传值的时候，如果是input就是value，如果是别的组件里的值，一般用text
                                            },
                                            type: "POST",
                                            dataType: "json",
                                            success: function (result) {
                                                if (result.status === 1) {

                                                    $.edbox({success: result.msg});
                                                    $.edbox('close');
                                                    initBillList();
                                                } else {
                                                    $.edbox({danger: result.msg});
                                                }
                                            },
                                            error: function () {
//                                                $.edbox({danger: "Got failed!"});
                                            }
                                        });

                                    }
        </script>

    </body>
</html>